package com.lzj.demo.design.factory;

import com.lzj.demo.design.factory.service.ICommodity;
import com.lzj.demo.design.factory.service.impl.CardCommodity;
import com.lzj.demo.design.factory.service.impl.CouponCommodity;
import com.lzj.demo.design.factory.service.impl.GoodsCommodity;

import java.util.Objects;

public class StoreFactory {
    public ICommodity getCommodityService(Integer commodityType){
        if(Objects.isNull(commodityType)){
            return null;
        }else if(commodityType.equals(1)){
            return new CouponCommodity();
        }else if(commodityType.equals(2)){
            return new GoodsCommodity();
        }else if(commodityType.equals(3)){
            return new CardCommodity();
        }
        throw new RuntimeException("不存在的奖品服务类型");
    }

    public ICommodity getCommodityService(Class<? extends ICommodity> clazz) throws InstantiationException, IllegalAccessException {
        if(Objects.isNull(clazz)){
            return null;
        }
        return clazz.newInstance();
    }
}
